package com.xfcy.blog.controller.system;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xfcy.blog.annotation.OperationLogger;
import com.xfcy.blog.common.R;
import com.xfcy.blog.service.impl.HomeServiceImpl;
import com.xfcy.blog.vo.SystemHardwareInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 晓风残月Lx
 * @date 2023/5/15 21:45
 */
@RestController
@RequestMapping("/system/home")
@Api(tags = "首页接口")
public class HomeController {

    @Resource
    private HomeServiceImpl homeService;

    @RequestMapping("/init")
    @ApiOperation(notes = "首页各种统计信息", httpMethod = "GET", response = R.class, value = "首页各种统计信息")
    @SaCheckLogin
    public R init() {
        return R.success(homeService.init());
    }

    @RequestMapping("/lineCount")
    @ApiOperation(notes = "首页文章、ip用户、留言统计", httpMethod = "GET", response = R.class, value = "首页文章、ip用户、留言统计")
    @SaCheckLogin
    public R lineCount() {
        return R.success(homeService.lineCount());
    }


    @RequestMapping(value = "/systemInfo", method = RequestMethod.GET)
    @ApiOperation(value = "服务监控列表", httpMethod = "GET", response = R.class, notes = "服务监控列表")
    @SaCheckPermission("/system/home/systemInfo")
    @OperationLogger(value = "服务监控列表")
    public R systemInfo() {
        SystemHardwareInfoVO systemHardwareInfoVO = new SystemHardwareInfoVO();
        systemHardwareInfoVO.copyTO();
        return R.success(systemHardwareInfoVO);
    }

    @GetMapping("/cache")
    @ApiOperation(value = "缓存监控列表", httpMethod = "GET", response = R.class, notes = "缓存监控列表")
    @SaCheckPermission("/system/home/cache")
    @OperationLogger(value = "缓存监控列表")
    public R cache() {
        return homeService.getCacheInfo();
    }



}
